<?php

/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/11/30 0030
 * Time: 9:20
 */
namespace APP\Tools;
class  Init
{

    protected  $openId;

    protected  $appSecret;
    protected  $baseUrl;
    protected  $uUid;
    public function __construct()
    {
        //初始配置

        //公用配置
        $this->openId =env('OPEN_ID');
        $this->appSecret = env('APP_SECRET');
        //测试环境
        $this->baseUrl = env('BASE_URL');

        //随机生成nonce
        $chars = md5(uniqid(mt_rand(), true));
        $uuid = substr($chars, 0, 8) . '-';
        $uuid .= substr($chars, 8, 4) . '-';
        $uuid .= substr($chars, 12, 4) . '-';
        $uuid .= substr($chars, 16, 4) . '-';
        $uuid .= substr($chars, 20, 12);
        $this->uUid = $uuid;
    }


    //公用方法
    function exec_post($url, $posts)
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($posts));

        $result = curl_exec($ch);
        if (!$result) {
            var_dump(curl_error($ch));
        }
        curl_close($ch);
        return json_decode($result, true);
    }


}